****************************************************************************************
*** Replication Code                                                                 ***
*** Title: Overestimation of the Level of Democracy among Citizens in Nondemocracies ***
*** Author: Eddy S. F. Yeung                                                         ***
*** Version: March 5, 2022                                                           ***
****************************************************************************************

*** Set-up ***
// Clean the Stata environment and set the working directory
// Stata version BE 17.0 for Mac (Intel 64-bit)
clear all
cd "~/Desktop/CPS_replication"
use "dataset_final.dta"
log using "main-analysis.smcl", replace

*** Table 2 ***
// Model 1: media freedom variable based on FOTP (w/o WGI controls)
eststo HLM1: mixed diff_dem_vdem new_fotp university ///
	female age age_sq married unemployed income social_class ///
	ln_gdp growth_one_yr || ///
	code: university, vce(cluster code) mle
estat ic

// Model 2: media freedom variable based on FOTP (w/ WGI controls)
eststo HLM2: mixed diff_dem_vdem new_fotp university ///
	female age age_sq married unemployed income social_class ///
	ln_gdp growth_one_yr new_rol new_gov || ///
	code: university, vce(cluster code) mle
estat ic

// Model 3: media freedom variable based on MSF (w/o WGI controls)
eststo HLM3: mixed diff_dem_vdem new_msf university ///
	female age age_sq married unemployed income social_class ///
	ln_gdp growth_one_yr || ///
	code: university, vce(cluster code) mle
estat ic

// Model 4: media freedom variable based on MSF (w WGI controls)
eststo HLM4: mixed diff_dem_vdem new_msf university ///
	female age age_sq married unemployed income social_class ///
	ln_gdp growth_one_yr new_rol new_gov || ///
	code: university, vce(cluster code) mle
estat ic

// Export table (Table 2 is modified from this exported table)
esttab HLM* using "~/Desktop/CPS_replication/tables/Table 2.tex", ///
	replace se b(4) star(* 0.10 ** 0.05 *** 0.01)
eststo clear

*** Figure 5 ***
// Set the plot scheme (run the two following lines to replicate the asethetics of the graphs)
* net install cleanplots, from("https://tdmize.github.io/data/cleanplots")
* set scheme cleanplots

// Panel A
mixed diff_dem_vdem c.internet##c.new_fotp ///
	university female age age_sq ///
	married unemployed income social_class ///
	ln_gdp growth_one_yr new_rol new_gov || ///
	code: university internet, vce(cluster code) mle
margins, at(new_fotp = (10 30 50) internet = (0 2 4)) atmeans vsquish
marginsplot, noci x(new_fotp) ///
	xtitle("Freedom of the Press") title("") ///
	xsize(4) legend(ring(0) pos(1)) plotopts(msize(large))
graph export "~/Desktop/CPS_replication/figures/Figure 5a.pdf", replace

// Panel B
mixed diff_dem_vdem c.internet##c.new_msf ///
	university female age age_sq ///
	married unemployed income social_class ///
	ln_gdp growth_one_yr new_rol new_gov || ///
	code: university internet, vce(cluster code) mle
margins, at(new_msf = (10 40 70) internet = (0 2 4)) atmeans vsquish
marginsplot, noci x(new_msf) ///
	xtitle("Media System Freedom") title("") ///
	xsize(4) legend(ring(0) pos(1)) plotopts(msize(large))
graph export "~/Desktop/CPS_replication/figures/Figure 5b.pdf", replace

/* Footnote 24: interaction effects with other information sources */
// Newspaper (p = 0.711 with FOTP; p = 0.221 with MSF)
mixed diff_dem_vdem c.newspaper##c.new_fotp ///
	university female age age_sq ///
	married unemployed income social_class ///
	ln_gdp growth_one_yr new_rol new_gov || ///
	code: university internet, vce(cluster code) mle
mixed diff_dem_vdem c.newspaper##c.new_msf ///
	university female age age_sq ///
	married unemployed income social_class ///
	ln_gdp growth_one_yr new_rol new_gov || ///
	code: university internet, vce(cluster code) mle
	
// TV (p = 0.716 with FOTP; p = 0.979 with MSF)
mixed diff_dem_vdem c.tv##c.new_fotp ///
	university female age age_sq ///
	married unemployed income social_class ///
	ln_gdp growth_one_yr new_rol new_gov || ///
	code: university internet, vce(cluster code) mle
mixed diff_dem_vdem c.tv##c.new_msf ///
	university female age age_sq ///
	married unemployed income social_class ///
	ln_gdp growth_one_yr new_rol new_gov || ///
	code: university internet, vce(cluster code) mle

// Radio (p = 0.846 with FOTP; p = 0.343 with MSF)
mixed diff_dem_vdem c.radio##c.new_fotp ///
	university female age age_sq ///
	married unemployed income social_class ///
	ln_gdp growth_one_yr new_rol new_gov || ///
	code: university internet, vce(cluster code) mle
mixed diff_dem_vdem c.radio##c.new_msf ///
	university female age age_sq ///
	married unemployed income social_class ///
	ln_gdp growth_one_yr new_rol new_gov || ///
	code: university internet, vce(cluster code) mle

*** Table S1 ***
** Generate a corresponding table for Figure 5
// Model 1
eststo MECH1: mixed diff_dem_vdem c.internet##c.new_fotp ///
	university female age age_sq ///
	married unemployed income social_class ///
	ln_gdp growth_one_yr || ///
	code: university internet, vce(cluster code) mle
estat ic

// Model 2
eststo MECH2: mixed diff_dem_vdem c.internet##c.new_fotp ///
	university female age age_sq ///
	married unemployed income social_class ///
	ln_gdp growth_one_yr new_rol new_gov || ///
	code: university internet, vce(cluster code) mle
estat ic

// Model 3
eststo MECH3: mixed diff_dem_vdem c.internet##c.new_msf ///
	university female age age_sq ///
	married unemployed income social_class ///
	ln_gdp growth_one_yr || ///
	code: university internet, vce(cluster code) mle
estat ic

// Model 4
eststo MECH4: mixed diff_dem_vdem c.internet##c.new_msf ///
	university female age age_sq ///
	married unemployed income social_class ///
	ln_gdp growth_one_yr new_rol new_gov || ///
	code: university internet, vce(cluster code) mle
estat ic

// Export table (Table S1 is modified from this exported table)
esttab MECH* using "~/Desktop/CPS_replication/tables/Table S1.tex", ///
	replace se b(4) star(* 0.10 ** 0.05 *** 0.01)
eststo clear

*** Table S2 ***
** Use the DV that is based on standardized Polyarchy and per_dem
// Model 1
eststo STD1: mixed diff_dem_vdem_z new_fotp university ///
	female age age_sq married unemployed income social_class ///
	ln_gdp growth_one_yr || ///
	code: university, vce(cluster code) mle
estat ic

// Model 2
eststo STD2: mixed diff_dem_vdem_z new_fotp university ///
	female age age_sq married unemployed income social_class ///
	ln_gdp growth_one_yr new_rol new_gov || ///
	code: university, vce(cluster code) mle
estat ic

// Model 3
eststo STD3: mixed diff_dem_vdem_z new_msf university ///
	female age age_sq married unemployed income social_class ///
	ln_gdp growth_one_yr || ///
	code: university, vce(cluster code) mle
estat ic

// Model 4
eststo STD4: mixed diff_dem_vdem_z new_msf university ///
	female age age_sq married unemployed income social_class ///
	ln_gdp growth_one_yr new_rol new_gov || ///
	code: university, vce(cluster code) mle
estat ic

// Export table (Table S2 is modified from this exported table)
esttab STD* using "~/Desktop/CPS_replication/tables/Table S2.tex", ///
	replace se b(4) star(* 0.10 ** 0.05 *** 0.01)
eststo clear

*** Table S3 ***
** Use the Polyarchy index that excludes the media freedom component
// Model 1
eststo EXC1: mixed diff_dem_new_vdem new_fotp university ///
	female age age_sq married unemployed income social_class ///
	ln_gdp growth_one_yr || ///
	code: university, vce(cluster code) mle
estat ic

// Model 2
eststo EXC2: mixed diff_dem_new_vdem new_fotp university ///
	female age age_sq married unemployed income social_class ///
	ln_gdp growth_one_yr new_rol new_gov || ///
	code: university, vce(cluster code) mle
estat ic

// Model 3
eststo EXC3: mixed diff_dem_new_vdem new_msf university ///
	female age age_sq married unemployed income social_class ///
	ln_gdp growth_one_yr || ///
	code: university, vce(cluster code) mle
estat ic

// Model 4
eststo EXC4: mixed diff_dem_new_vdem new_msf university ///
	female age age_sq married unemployed income social_class ///
	ln_gdp growth_one_yr new_rol new_gov || ///
	code: university, vce(cluster code) mle
estat ic

// Export table (Table S3 is modified from this exported table)
esttab EXC* using "~/Desktop/CPS_replication/tables/Table S3.tex", ///
	replace se b(4) star(* 0.10 ** 0.05 *** 0.01)
eststo clear

*** Table S8 ***
// Generate a variable for individual confidence in courts
gen court_conf = .
replace court_conf = 0 if V114 == 4
replace court_conf = 1 if V114 == 3
replace court_conf = 2 if V114 == 2
replace court_conf = 3 if V114 == 1

// Generate a variable for individual confidence in government
gen govt_conf = .
replace govt_conf = 0 if V115 == 4
replace govt_conf = 1 if V115 == 3
replace govt_conf = 2 if V115 == 2
replace govt_conf = 3 if V115 == 1

// Generate a variable for individual confidence in civil service
gen civil_conf = .
replace civil_conf = 0 if V118 == 4
replace civil_conf = 1 if V118 == 3
replace civil_conf = 2 if V118 == 2
replace civil_conf = 3 if V118 == 1

// Run the main analyses but control for confidence in courts, government, and civil service
// Model 1
eststo CON1: mixed diff_dem_vdem new_fotp university ///
	court_conf govt_conf civil_conf ///
	female age age_sq married unemployed income social_class ///
	ln_gdp growth_one_yr || ///
	code: university, vce(cluster code) mle
estat ic

// Model 2
eststo CON2: mixed diff_dem_vdem new_fotp university ///
	court_conf govt_conf civil_conf ///
	female age age_sq married unemployed income social_class ///
	ln_gdp growth_one_yr new_rol new_gov || ///
	code: university, vce(cluster code) mle
estat ic

// Model 3
eststo CON3: mixed diff_dem_vdem new_msf university ///
	court_conf govt_conf civil_conf ///
	female age age_sq married unemployed income social_class ///
	ln_gdp growth_one_yr || ///
	code: university, vce(cluster code) mle
estat ic

// Model 4
eststo CON4: mixed diff_dem_vdem new_msf university ///
	court_conf govt_conf civil_conf ///
	female age age_sq married unemployed income social_class ///
	ln_gdp growth_one_yr new_rol new_gov || ///
	code: university, vce(cluster code) mle
estat ic

// Export table (Table S8 is modified from this exported table)
esttab CON* using "~/Desktop/CPS_replication/tables/Table S8.tex", ///
	replace se b(4) star(* 0.10 ** 0.05 *** 0.01)
eststo clear

*** Table S9 ***
// Require ado files "cgmwildboot.ado" and "cgmreg.ado"
// Model 1
eststo WB1: cgmwildboot diff_dem_vdem new_fotp university ///
	female age age_sq married unemployed income social_class ///
	ln_gdp growth_one_yr, cluster(code) ///
	bootcluster(code) seed(1234567) reps(400)

// Model 2
eststo WB2: cgmwildboot diff_dem_vdem new_fotp university ///
	female age age_sq married unemployed income social_class ///
	ln_gdp growth_one_yr new_rol new_gov, cluster(code) ///
	bootcluster(code) seed(1234567) reps(400)

// Model 3
eststo WB3: cgmwildboot diff_dem_vdem new_msf university ///
	female age age_sq married unemployed income social_class ///
	ln_gdp growth_one_yr, cluster(code) ///
	bootcluster(code) seed(1234567) reps(400)

// Model 4
eststo WB4: cgmwildboot diff_dem_vdem new_msf university ///
	female age age_sq married unemployed income social_class ///
	ln_gdp growth_one_yr new_rol new_gov, cluster(code) ///
	bootcluster(code) seed(1234567) reps(400)

// Export table (Table S9 is modified from this exported table)
esttab WB* using "~/Desktop/CPS_replication/tables/Table S9.tex", ///
	replace se b(4) ar2 star(* 0.10 ** 0.05 *** 0.01)
eststo clear

*** Table S4 ***
// Model 1
eststo MLR1: melogit overest_vdem new_fotp university ///
	female age age_sq married unemployed income social_class ///
	ln_gdp growth_one_yr || ///
	code: university
estat ic

// Model 2
eststo MLR2: melogit overest_vdem new_fotp university ///
	female age age_sq married unemployed income social_class ///
	ln_gdp growth_one_yr new_rol new_gov || ///
	code: university
estat ic

// Model 3
eststo MLR3: melogit overest_vdem new_msf university ///
	female age age_sq married unemployed income social_class ///
	ln_gdp growth_one_yr || ///
	code: university
estat ic

// Model 4
eststo MLR4: melogit overest_vdem new_msf university ///
	female age age_sq married unemployed income social_class ///
	ln_gdp growth_one_yr new_rol new_gov || ///
	code: university
estat ic

// Export table (Table S4 is modified from this exported table)
esttab MLR* using "~/Desktop/CPS_replication/tables/Table S4.tex", ///
	replace se b(4) star(* 0.10 ** 0.05 *** 0.01)

*** Table S5 ***
// Model 1
eststo HR1: mixed diff_dem_vdem new_fotp university ///
	female age age_sq married unemployed income social_class ///
	ln_gdp growth_one_yr HRPS || ///
	code: university, vce(cluster code) mle
estat ic

// Model 2
eststo HR2: mixed diff_dem_vdem new_fotp university ///
	female age age_sq married unemployed income social_class ///
	ln_gdp growth_one_yr new_rol new_gov HRPS || ///
	code: university, vce(cluster code) mle
estat ic

// Model 3
eststo HR3: mixed diff_dem_vdem new_msf university ///
	female age age_sq married unemployed income social_class ///
	ln_gdp growth_one_yr HRPS || ///
	code: university, vce(cluster code) mle
estat ic

// Model 4
eststo HR4: mixed diff_dem_vdem new_msf university ///
	female age age_sq married unemployed income social_class ///
	ln_gdp growth_one_yr new_rol new_gov HRPS || ///
	code: university, vce(cluster code) mle
estat ic

// Export table (Table S5 is modified from this exported table)
esttab HR* using "~/Desktop/CPS_replication/tables/Table S5.tex", ///
	replace se b(4) star(* 0.10 ** 0.05 *** 0.01)
eststo clear

*** Other robustness checks ***
** References in "rob-check_summary.xlsx": rob_check >= 1 & rob_check <= 6
/* Conduct placebo and horse race tests with free and fair elections (v2xel_frefair) */
// Rescale v2xel_frefair so that it ranges from 0 to 100
gen elec_frefair = v2xel_frefair * 100

// Model 1: placebo test (without media freedom)
eststo FRE1: mixed diff_dem_vdem elec_frefair university ///
	female age age_sq married unemployed income social_class ///
	ln_gdp growth_one_yr || ///
	code: university, vce(cluster code) mle

// Model 2: placebo test (but with binary DV)
eststo FRE2: melogit overest_vdem elec_frefair university ///
	female age age_sq married unemployed income social_class ///
	ln_gdp growth_one_yr || ///
	code: university

// Model 3: horse race test (with FOTP)
eststo FRE3: mixed diff_dem_vdem elec_frefair new_fotp university ///
	female age age_sq married unemployed income social_class ///
	ln_gdp growth_one_yr || ///
	code: university, vce(cluster code) mle

// Model 4: horse race test (with MSF)
eststo FRE4: mixed diff_dem_vdem elec_frefair new_msf university ///
	female age age_sq married unemployed income social_class ///
	ln_gdp growth_one_yr || ///
	code: university, vce(cluster code) mle
eststo clear

** References in "rob-check_summary.xlsx": rob_check >= 1 & rob_check <= 6
/* Conduct placebo and horse race tests with elected officials index (v2x_elecoff) */
// Rescale v2x_elecoff so that it ranges from 0 to 100
gen elec_official = v2x_elecoff * 100

// Model 1: placebo test (without media freedom)
eststo ELE1: mixed diff_dem_vdem elec_official university ///
	female age age_sq married unemployed income social_class ///
	ln_gdp growth_one_yr || ///
	code: university, vce(cluster code) mle

// Model 2: placebo test (but with binary DV)
eststo FRE2: melogit overest_vdem elec_official university ///
	female age age_sq married unemployed income social_class ///
	ln_gdp growth_one_yr || ///
	code: university

// Model 3: horse race test (with FOTP)
eststo ELE3: mixed diff_dem_vdem elec_official new_fotp university ///
	female age age_sq married unemployed income social_class ///
	ln_gdp growth_one_yr || ///
	code: university, vce(cluster code) mle

// Model 4: horse race test (with MSF)
eststo ELE4: mixed diff_dem_vdem elec_official new_msf university ///
	female age age_sq married unemployed income social_class ///
	ln_gdp growth_one_yr || ///
	code: university, vce(cluster code) mle
eststo clear

** Reference in "rob-check_summary.xlsx": rob_check == 7
/* Drop individuals who believe democracy is unimportant (threshold = 6) */
eststo UNIM1: mixed diff_dem_vdem new_fotp university ///
	female age age_sq married unemployed income social_class ///
	ln_gdp growth_one_yr new_rol new_gov if V140 > 5 || ///
	code: university, vce(cluster code) mle
eststo UNIM2: mixed diff_dem_vdem new_msf university ///
	female age age_sq married unemployed income social_class ///
	ln_gdp growth_one_yr new_rol new_gov if V140 > 5 || ///
	code: university, vce(cluster code) mle
eststo clear

** Reference in "rob-check_summary.xlsx": rob_check == 8
/* Drop individuals who believe democracy is unimportant (threshold = 10) */
eststo UNIM3: mixed diff_dem_vdem new_fotp university ///
	female age age_sq married unemployed income social_class ///
	ln_gdp growth_one_yr new_rol new_gov if V140 == 10 || ///
	code: university, vce(cluster code) mle
eststo UNIM4: mixed diff_dem_vdem new_msf university ///
	female age age_sq married unemployed income social_class ///
	ln_gdp growth_one_yr new_rol new_gov if V140 == 10 || ///
	code: university, vce(cluster code) mle
eststo clear

** References in "rob-check_summary.xlsx": rob_check >= 9 & rob_check <= 14
/* Use other democracy indices */
// Use vdem_libdem
eststo OTH1: mixed diff_dem_libdem new_fotp university ///
	female age age_sq married unemployed income social_class ///
	ln_gdp growth_one_yr new_rol new_gov || ///
	code: university, vce(cluster code) mle
eststo OTH2: mixed diff_dem_libdem new_msf university ///
	female age age_sq married unemployed income social_class ///
	ln_gdp growth_one_yr new_rol new_gov || ///
	code: university, vce(cluster code) mle

// Use vdem_partipdem
eststo OTH3: mixed diff_dem_partipdem new_fotp university ///
	female age age_sq married unemployed income social_class ///
	ln_gdp growth_one_yr new_rol new_gov || ///
	code: university, vce(cluster code) mle
eststo OTH4: mixed diff_dem_partipdem new_msf university ///
	female age age_sq married unemployed income social_class ///
	ln_gdp growth_one_yr new_rol new_gov || ///
	code: university, vce(cluster code) mle

// Use vdem_delibdem
eststo OTH5: mixed diff_dem_delibdem new_fotp university ///
	female age age_sq married unemployed income social_class ///
	ln_gdp growth_one_yr new_rol new_gov || ///
	code: university, vce(cluster code) mle
eststo OTH6: mixed diff_dem_delibdem new_msf university ///
	female age age_sq married unemployed income social_class ///
	ln_gdp growth_one_yr new_rol new_gov || ///
	code: university, vce(cluster code) mle

// Use vdem_egaldem
eststo OTH7: mixed diff_dem_egaldem new_fotp university ///
	female age age_sq married unemployed income social_class ///
	ln_gdp growth_one_yr new_rol new_gov || ///
	code: university, vce(cluster code) mle
eststo OTH8: mixed diff_dem_egaldem new_msf university ///
	female age age_sq married unemployed income social_class ///
	ln_gdp growth_one_yr new_rol new_gov || ///
	code: university, vce(cluster code) mle

// Use Polity5
eststo OTH9: mixed diff_dem_polity new_fotp university ///
	female age age_sq married unemployed income social_class ///
	ln_gdp growth_one_yr new_rol new_gov || ///
	code: university, vce(cluster code) mle
eststo OTH10: mixed diff_dem_polity new_msf university ///
	female age age_sq married unemployed income social_class ///
	ln_gdp growth_one_yr new_rol new_gov || ///
	code: university, vce(cluster code) mle

// Use Freedom in the World
eststo OTH11: mixed diff_dem_fitw new_fotp university ///
	female age age_sq married unemployed income social_class ///
	ln_gdp growth_one_yr new_rol new_gov || ///
	code: university, vce(cluster code) mle
eststo OTH12: mixed diff_dem_fitw new_msf university ///
	female age age_sq married unemployed income social_class ///
	ln_gdp growth_one_yr new_rol new_gov || ///
	code: university, vce(cluster code) mle
eststo clear

** Reference in "rob-check_summary.xlsx": rob_check == 15
/* Drop respondents from particular countries */
// Drop Chinese respondents
eststo CHN1: mixed diff_dem_vdem new_fotp university ///
	female age age_sq married unemployed income social_class ///
	ln_gdp growth_one_yr new_rol new_gov if code != 156 || ///
	code: university, vce(cluster code) mle
eststo CHN2: mixed diff_dem_vdem new_msf university ///
	female age age_sq married unemployed income social_class ///
	ln_gdp growth_one_yr new_rol new_gov if code != 156 || ///
	code: university, vce(cluster code) mle
eststo clear

** Reference in "rob-check_summary.xlsx": rob_check == 16
// Drop Russian respondents
eststo RUS1: mixed diff_dem_vdem new_fotp university ///
	female age age_sq married unemployed income social_class ///
	ln_gdp growth_one_yr new_rol new_gov if code != 643 || ///
	code: university, vce(cluster code) mle
eststo RUS2: mixed diff_dem_vdem new_msf university ///
	female age age_sq married unemployed income social_class ///
	ln_gdp growth_one_yr new_rol new_gov if code != 643 || ///
	code: university, vce(cluster code) mle
eststo clear

** Reference in "rob-check_summary.xlsx": rob_check == 17
// Drop Chinese and Russian respondents
eststo CNR1: mixed diff_dem_vdem new_fotp university ///
	female age age_sq married unemployed income social_class ///
	ln_gdp growth_one_yr new_rol new_gov if code != 156 & code != 643 || ///
	code: university, vce(cluster code) mle
eststo CNR2: mixed diff_dem_vdem new_msf university ///
	female age age_sq married unemployed income social_class ///
	ln_gdp growth_one_yr new_rol new_gov if code != 156 & code != 643 || ///
	code: university, vce(cluster code) mle
eststo clear

** Reference in "rob-check_summary.xlsx": rob_check == 18
// Drop Pakistani, Thai, and Ukrainian respondents
eststo PTU1: mixed diff_dem_vdem new_fotp university ///
	female age age_sq married unemployed income social_class ///
	ln_gdp growth_one_yr new_rol new_gov ///
	if code != 586 & code != 764 & code != 804 || ///
	code: university, vce(cluster code) mle
eststo PTU2: mixed diff_dem_vdem new_msf university ///
	female age age_sq married unemployed income social_class ///
	ln_gdp growth_one_yr new_rol new_gov ///
	if code != 586 & code != 764 & code != 804 || ///
	code: university, vce(cluster code) mle
eststo clear

** Reference in "rob-check_summary.xlsx": rob_check == 19
/* Address concerns about preference falsification */
// Drop high-income respondents (who are more likely to lie in nondemocracies)
eststo PF1: mixed diff_dem_vdem new_fotp university ///
	female age age_sq married unemployed income social_class ///
	ln_gdp growth_one_yr new_rol new_gov if income <= 6 || ///
	code: university, vce(cluster code) mle
eststo PF2: mixed diff_dem_vdem new_msf university ///
	female age age_sq married unemployed income social_class ///
	ln_gdp growth_one_yr new_rol new_gov if income <= 6 || ///
	code: university, vce(cluster code) mle
eststo clear

** Reference in "rob-check_summary.xlsx": rob_check == 20
// Drop respondents who rated themselves as upper or upper middle class (based on V238)
eststo PF5: mixed diff_dem_vdem new_fotp university ///
	female age age_sq married unemployed income social_class ///
	ln_gdp growth_one_yr new_rol new_gov if V238 != 1 & V238 != 2 || ///
	code: university, vce(cluster code) mle
eststo PF6: mixed diff_dem_vdem new_msf university ///
	female age age_sq married unemployed income social_class ///
	ln_gdp growth_one_yr new_rol new_gov if V238 != 1 & V238 != 2 || ///
	code: university, vce(cluster code) mle
eststo clear

** Reference in "rob-check_summary.xlsx": rob_check == 21
// Drop respondents who worried about government monitoring (based on V186)
eststo PF3: mixed diff_dem_vdem new_fotp university ///
	female age age_sq married unemployed income social_class ///
	ln_gdp growth_one_yr new_rol new_gov if V186 != 1 & V186 != 2 || ///
	code: university, vce(cluster code) mle
eststo PF4: mixed diff_dem_vdem new_msf university ///
	female age age_sq married unemployed income social_class ///
	ln_gdp growth_one_yr new_rol new_gov if V186 != 1 & V186 != 2 || ///
	code: university, vce(cluster code) mle
eststo clear

** Reference in "rob-check_summary.xlsx": rob_check == 22
// Drop respondents who had other people around who could follow the interview (based on V252)
eststo PF7: mixed diff_dem_vdem new_fotp university ///
	female age age_sq married unemployed income social_class ///
	ln_gdp growth_one_yr new_rol new_gov if V252 != 2 || ///
	code: university, vce(cluster code) mle
eststo PF8: mixed diff_dem_vdem new_msf university ///
	female age age_sq married unemployed income social_class ///
	ln_gdp growth_one_yr new_rol new_gov if V252 != 2 || ///
	code: university, vce(cluster code) mle
eststo clear

** Reference in "rob-check_summary.xlsx": rob_check == 23
// Drop most repressive regimes (based on political terror scale)
eststo PF9: mixed diff_dem_vdem new_fotp university ///
	female age age_sq married unemployed income social_class ///
	ln_gdp growth_one_yr new_rol new_gov if PTS != 5 || ///
	code: university, vce(cluster code) mle
eststo PF10: mixed diff_dem_vdem new_msf university ///
	female age age_sq married unemployed income social_class ///
	ln_gdp growth_one_yr new_rol new_gov if PTS != 5 || ///
	code: university, vce(cluster code) mle
eststo clear

** Reference in "rob-check_summary.xlsx": rob_check == 24
/* Drop respondents whose conceptions of democracy are different from expert coders' */
// Preferred specification (discussed in the main text)
eststo COD1: mixed diff_dem_vdem new_fotp university ///
	female age age_sq married unemployed income social_class ///
	ln_gdp growth_one_yr new_rol new_gov ///
	if V131 < 10 & V132 < 10 & V133 > 5 & V134 < 10 & ///
	V135 < 10 & V137 < 10 & V138 < 10 || ///
	code: university, vce(cluster code) mle
eststo COD2: mixed diff_dem_vdem new_msf university ///
	female age age_sq married unemployed income social_class ///
	ln_gdp growth_one_yr new_rol new_gov ///
	if V131 < 10 & V132 < 10 & V133 > 5 & V134 < 10 & ///
	V135 < 10 & V137 < 10 & V138 < 10 || ///
	code: university, vce(cluster code) mle
eststo clear

** Reference in "rob-check_summary.xlsx": rob_check == 25
// Ease the restriction from "10" to "9"
eststo COD3: mixed diff_dem_vdem new_fotp university ///
	female age age_sq married unemployed income social_class ///
	ln_gdp growth_one_yr new_rol new_gov ///
	if V131 < 9 & V132 < 9 & V133 > 5 & V134 < 9 & ///
	V135 < 9 & V137 < 9 & V138 < 9 || ///
	code: university, vce(cluster code) mle
eststo COD4: mixed diff_dem_vdem new_msf university ///
	female age age_sq married unemployed income social_class ///
	ln_gdp growth_one_yr new_rol new_gov ///
	if V131 < 9 & V132 < 9 & V133 > 5 & V134 < 9 & ///
	V135 < 9 & V137 < 9 & V138 < 9 || ///
	code: university, vce(cluster code) mle
eststo clear

** Reference in "rob-check_summary.xlsx": rob_check == 26
// Further ease the restriction from "9" to "8"
eststo COD5: mixed diff_dem_vdem new_fotp university ///
	female age age_sq married unemployed income social_class ///
	ln_gdp growth_one_yr new_rol new_gov ///
	if V131 < 8 & V132 < 8 & V133 > 5 & V134 < 8 & ///
	V135 < 8 & V137 < 8 & V138 < 8 || ///
	code: university, vce(cluster code) mle
eststo COD6: mixed diff_dem_vdem new_msf university ///
	female age age_sq married unemployed income social_class ///
	ln_gdp growth_one_yr new_rol new_gov ///
	if V131 < 8 & V132 < 8 & V133 > 5 & V134 < 8 & ///
	V135 < 8 & V137 < 8 & V138 < 8 || ///
	code: university, vce(cluster code) mle
eststo clear

** Reference in "rob-check_summary.xlsx": rob_check == 27
// Only include respondents who rate free elections (V133) as strictly higher
// than all one of the other "strange" items (V131, V132, V134, V135, V137, V138)
gen include1 = 0
replace include1 = 1 if V133 > V131 & V133 > V132 & V133 > V134 ///
	& V133 > V135 & V133 > V137 & V133 > V138
eststo DRP1: mixed diff_dem_vdem new_fotp university ///
	female age age_sq married unemployed income social_class ///
	ln_gdp growth_one_yr new_rol new_gov ///
	if include1 == 1 || ///
	code: university, vce(cluster code) mle
eststo DRP2: mixed diff_dem_vdem new_msf university ///
	female age age_sq married unemployed income social_class ///
	ln_gdp growth_one_yr new_rol new_gov ///
	if include1 == 1 || ///
	code: university, vce(cluster code) mle
eststo clear

** Reference in "rob-check_summary.xlsx": rob_check == 28
// Only include respondents who rate civil rights protection (V136) as strictly higher
// than all one of the other "strange" items (V131, V132, V134, V135, V137, V138)
gen include2 = 0
replace include2 = 1 if V136 > V131 & V136 > V132 & V136 > V134 ///
	& V136 > V135 & V136 > V137 & V136 > V138
eststo DRP3: mixed diff_dem_vdem new_fotp university ///
	female age age_sq married unemployed income social_class ///
	ln_gdp growth_one_yr new_rol new_gov ///
	if include2 == 1 || ///
	code: university, vce(cluster code) mle
eststo DRP4: mixed diff_dem_vdem new_msf university ///
	female age age_sq married unemployed income social_class ///
	ln_gdp growth_one_yr new_rol new_gov ///
	if include2 == 1 || ///
	code: university, vce(cluster code) mle
eststo clear

** Reference in "rob-check_summary.xlsx": rob_check == 29
// Only include respondents who rate the mean of free elections and civil rights 
// protection as strictly higher than the mean of all other "strange" items
gen mean_nonstrange = .
replace mean_nonstrange = (V133 + V136) / 2 ///
	if V133 > 0 & V136 > 0
gen mean_strange = .
replace mean_strange = (V131 + V132 + V134 + V135 + V137 + V138) / 6 ///
	if V131 > 0 & V132 > 0 & V134 > 0 & V135 > 0 & V137 > 0 & V138 > 0
gen include3 = 0
replace include3 = 1 if mean_strange > mean_nonstrange
eststo DRP5: mixed diff_dem_vdem new_fotp university ///
	female age age_sq married unemployed income social_class ///
	ln_gdp growth_one_yr new_rol new_gov ///
	if include3 == 1 || ///
	code: university, vce(cluster code) mle
eststo DRP6: mixed diff_dem_vdem new_msf university ///
	female age age_sq married unemployed income social_class ///
	ln_gdp growth_one_yr new_rol new_gov ///
	if include3 == 1 || ///
	code: university, vce(cluster code) mle
eststo clear
	
*** Figure S18 ***
* ssc install binscatter
// Panel A
binscatter diff_dem_vdem new_fotp, ///
	controls(university female age age_sq married unemployed ///
	income social_class ln_gdp growth_one_yr new_rol new_gov) ///
	xtitle(Freedom of the Press (Residualized)) ytitle(Degree of Overestimation (Residualized)) ///
	xscale(range(0 60)) yscale(range(-1 4)) ///
	ylabel(#6) xlabel(#6) ysize(5) xsize(5)
graph export "~/Desktop/CPS_replication/figures/Figure S18a.pdf", replace

// Panel B
binscatter diff_dem_vdem new_msf, ///
	controls(university female age age_sq married unemployed ///
	income social_class ln_gdp growth_one_yr new_rol new_gov) ///
	xtitle(Media System Freedom (Residualized)) ytitle(Degree of Overestimation (Residualized)) ///
	xscale(range(0 80)) yscale(range(-1 4)) ///
	ylabel(#6) xlabel(#6) ysize(5) xsize(5)
graph export "~/Desktop/CPS_replication/figures/Figure S18b.pdf", replace

*** Page S11 of Supplemental Appendix ***
/* Electoral fraud, Internet censorship, and Internet consumption */
// Drop countries that are not asked a full set of questions about electoral fairness
drop if code == 51 | code == 112 | code == 156 | code == 400 | code == 504 | code == 643

// Code perceptions of the electoral process using V228A to V228I in WVS
gen fairness1 = .
replace fairness1 = 0 if V228A == 4
replace fairness1 = 1 if V228A == 3
replace fairness1 = 2 if V228A == 2
replace fairness1 = 3 if V228A == 1

gen fairness2 = .
replace fairness2 = 0 if V228B == 1
replace fairness2 = 1 if V228B == 2
replace fairness2 = 2 if V228B == 3
replace fairness2 = 3 if V228B == 4

gen fairness3 = .
replace fairness3 = 0 if V228C == 1
replace fairness3 = 1 if V228C == 2
replace fairness3 = 2 if V228C == 3
replace fairness3 = 3 if V228C == 4

gen fairness4 = .
replace fairness4 = 0 if V228D == 1
replace fairness4 = 1 if V228D == 2
replace fairness4 = 2 if V228D == 3
replace fairness4 = 3 if V228D == 4

gen fairness5 = .
replace fairness5 = 0 if V228E == 4
replace fairness5 = 1 if V228E == 3
replace fairness5 = 2 if V228E == 2
replace fairness5 = 3 if V228E == 1

gen fairness6 = .
replace fairness6 = 0 if V228F == 4
replace fairness6 = 1 if V228F == 3
replace fairness6 = 2 if V228F == 2
replace fairness6 = 3 if V228F == 1

gen fairness7 = .
replace fairness7 = 0 if V228G == 1
replace fairness7 = 1 if V228G == 2
replace fairness7 = 2 if V228G == 3
replace fairness7 = 3 if V228G == 4

gen fairness8 = .
replace fairness8 = 0 if V228H == 1
replace fairness8 = 1 if V228H == 2
replace fairness8 = 2 if V228H == 3
replace fairness8 = 3 if V228H == 4

gen fairness9 = .
replace fairness9 = 0 if V228I == 4
replace fairness9 = 1 if V228I == 3
replace fairness9 = 2 if V228I == 2
replace fairness9 = 3 if V228I == 1

// Predict the missing values using multiple imputation
mi set wide
mi register imputed fairness1-fairness9
set seed 1234567
mi impute mvn fairness1-fairness9, add(1)

// Create an electoral fairness index using principal component analysis
pca _1_fairness1-_1_fairness9
predict per_fairness_pca, score

// Regress the electoral fairness index on Internet consumption and university
// education, along with country-fixed effects (which remove unobserved
// between-group heterogeneity)
// Cluster standard errors are not needed here because each within-group 
// observation can be considered as an i.i.d. draw from their larger group
reg per_fairness_pca internet university ///
	female age age_sq married unemployed income social_class ///
	i.code, robust

log close
